/*与补助相关的补助查询和补助状态*/
require.config({
    paths: {
        "common": "../common/common"
    }
});
define(['common'], function(common) {
    console.log(common)
    var baseUrl = common.defaultStr();
    var buzhu_url = {
        'delBuzhu': baseUrl + '/usr/buzhu/remove.do',
        'addBuzhu': baseUrl + '/usr/buzhu/addBuZhuCheck.do',
        'addBuzhu_without': baseUrl + '/usr/buzhu/addBuZhuWithoutCheck.do',
        // 'queryBuZhu': baseUrl + "/usr/buzhu/searchBuzhuByPage1.do",
        'queryBuZhu': baseUrl + "/usr/buzhu/searchBuzhuByPage.do",

        'submit': baseUrl + '/usr/buzhu/submit.do',
        'agree': baseUrl + '/usr/buzhu/agree.do',
        'disagree': baseUrl + '/usr/buzhu/disagree.do'
    };

    function addBuzhuWithout(query) {
        return $.ajax({
            type: "POST",
            url: buzhu_url.addBuzhu_without,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(query),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function addBuzhu(query) {
        return $.ajax({
            type: "POST",
            url: buzhu_url.addBuzhu,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(query),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function delBuzhu(query) {
        return $.ajax({
            type: "POST",
            url: buzhu_url.queryZG,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(_self.query),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,

        }).done(
            handleSessionTimeOut
        );
    }
    /*根据状态，学院查询补助审核状态*/
    function queryBuZhuStatus(query) {
        return $.ajax({
            type: "POST",
            url: buzhu_url.queryBuZhu,
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function submitData(id) {
        var newUrl = buzhu_url.submit + '?' + 'buzhuList=' + id;
        return $.ajax({
            type: "POST",
            url: newUrl,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut);
    }

    function agreeBuzhu(arr) {
        var id = common.arrayToStr(arr);
        var newUrl = buzhu_url.agree + '?' + 'buzhuList=' + id;
        return $.ajax({
            type: "POST",
            url: newUrl,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function disagreeBuzhu(arr) {
        var id = common.arrayToStr(arr);
        var newUrl = buzhu_url.disagree + '?' + 'buzhuList=' + id;
        return $.ajax({
            type: "POST",
            url: newUrl,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function handleSessionTimeOut(data) {
        if (data && data.retcode === '202') {
            location.reload();
        }
    }
    return {
        addBZW: addBuzhuWithout,
        addBZ: addBuzhu,
        delBZ: delBuzhu,
        queryBuZhu: queryBuZhuStatus,
        submitBZ: submitData,
        agree: agreeBuzhu,
        disagree: disagreeBuzhu
    }
})
